<template>
  <div id="cornerComment" v-if="dialogVisible">
    <div class="cornerComment-in" ref="dialogBox">
      <div class="cornerComment-in-title">
        <span>编辑全日健康</span>
        <span class="el-icon-circle-close close-Btn-line" @click="closePOpup"></span>
      </div>
      <div class="commentBody">
        <div class="allday-box">
          <div class="allday-box-left">
            <div style="height:50px;display: flex;align-items: center;margin-right: 10px">
              <div>
                <component
                    v-bind:is="item.propertyType"
                    :property.sync="item"
                    v-for="(item, index) in getPower"
                    :key="index"
                    @updateVal="updateVal"
                ></component>
              </div>
              <el-button type="primary" size="small" @click="getStudentFn">查询
              </el-button>
              <el-button size="small" @click="searchFn">重置刷新</el-button>
            </div>
            <div class="allday-student" :style="{height: tableHeight+'px'}" v-if="studentList.length">
              <div class="allday-student-list" v-for="item in studentList" :key="item.id">
                <div class="allday-student-list-in" @click="getStudentInfo(item)"
                     :class="{active:studentOption&&studentOption.id==item.id}">
                  {{ item.name }}
                </div>
              </div>
            </div>
            <div class="allday-student" :style="{height: tableHeight+'px'}" v-else>
              <div class="none-data-student">
                暂无班级学生信息
              </div>
            </div>
          </div>
          <div class="allday-box-right">
            <el-form :model="infoForm" label-width="90px" ref="editForm">
              <el-form-item label="学生姓名：">
                {{ studentOption ? studentOption.name : '--' }}
              </el-form-item>
              <el-form-item label="检查日期：">
                <el-date-picker
                    v-model="infoForm.day"
                    type="date"
                    :picker-options="pickerOptions1"
                    placeholder="选择日期"
                    value-format="yyyy-MM-dd"
                    size="small"
                    class="w-140"
                ></el-date-picker>
              </el-form-item>
              <el-form-item label="健康状况：">
                <el-input
                    type="textarea"
                    placeholder="健康状况"
                    v-model="infoForm.healthy"
                    maxlength="100"
                    show-word-limit
                    rows="5"
                >
                </el-input>
              </el-form-item>
              <el-form-item label="处理：" prop="num">
                <el-input
                    type="textarea"
                    placeholder="处理"
                    v-model="infoForm.handle"
                    maxlength="100"
                    show-word-limit
                    rows="5"
                >
                </el-input>
              </el-form-item>
            </el-form>
          </div>
        </div>
      </div>
      <div class="cornerComment-in-footer">
        <el-button @click.native="closePOpup" size="small">取消</el-button>
        <el-button size="small" type="primary" @click="checkEditFn">确定并提交</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import {yeartime} from "@/assets/js/common";
import {classesStudent} from "@/api/admin/student"
import {dayCheckAdd} from "@/api/admin/ClassDynamics"

export default {
  props: ['visible'], // recruitmentType examine 审核
  components: {},
  data() {
    return {
      dialogVisible: false,
      infoForm: {
        student_id: '', //学生id
        day: yeartime(new Date()), // 检查日期
        healthy: '', // 健康状况
        handle: '' // 处理
      },
      tableHeight: 0,
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() < Date.now()
        }
      },
      searchBox: {
        section_id: '',
        class_id: ''
      },
      getPower: {
        'section_id': {
          name: 'section_id', // key名称
          default: '', // 默认值
          propertyType: "Select", // 组件名称
          placeholder: '年段', // 默认值
          valueText: '', // 值
          leve: 2,
          api: this.api.user_sectionindex, // 下拉框的请求接口
          keyName: 'section_name',// 调用的字段
          child: [
            {
              name: 'class_id',
              default: '',
              propertyType: "",
              placeholder: '班级',
              valueText: '',
              api: this.api.user_classesindex,
              keyName: 'class_name',
            }
          ]
        }
      },
      studentList: [],
      studentOption: null
    }
  },
  watch: {
    visible() {
      this.dialogVisible = this.visible
      if (!this.visible) {
        this.searchFn()

      } else {
        let n = this
        this.$nextTick(() => {
          let height = n.$refs.dialogBox.offsetHeight;  //top 50 1 search 50 page 50 10 footer 50 1
          n.tableHeight = height - (51 + 20 + 51 + 50)
        })
      }
    }
  },
  created() {

  },
  methods: {
    getStudentFn() {
      classesStudent(this.searchBox).then(res => {
        console.log('学生信息：', res)
        this.studentList = res.list
      })
    },
    getStudentInfo(item) {
      this.studentOption = JSON.parse(JSON.stringify(item))
    },
    searchFn() {
      let newGetPower = JSON.parse(JSON.stringify(this.getPower))
      newGetPower['section_id'].valueText = '';
      newGetPower['section_id'].child[0].valueText = '';
      this.getPower = newGetPower;
      this.searchBox.class_id = '';
      this.searchBox.section_id = '';
      this.studentList = []
      this.studentOption = null
      this.infoForm = {
        student_id: '', //学生id
        day: yeartime(new Date()), // 检查日期
        healthy: '', // 健康状况
        handle: '' // 处理
      }
    },
    // 更新值
    updateVal(option) {
      // console.log('变更数据收到的数据内容：', option)
      if (option.input) {
        this.searchBox[option['input'].name] = option['input'].valueText
      } else if (option.select) {
        for (let i in option.select) {
          if (option.select[i].name) {
            this.searchBox[option.select[i].name] = option.select[i].valueText
          } else {
            this.searchBox[option.select[i - 1].name] = option.select[i].valueText ? option.select[i].valueText : option.select[i - 1].valueText
          }
        }
      }
    },
    checkEditFn() {
      if (!this.studentOption) {
        this.$message.error('选择需要检查的学生信息');
        return
      }
      if (!this.infoForm.day) {
        this.$message.error('选择检查日期');
        return
      }
      let data_ = JSON.parse(JSON.stringify(this.infoForm))
      data_.student_id = this.studentOption.id
      dayCheckAdd(data_).then(res => {
        console.log('res:', res)
        if (!res.code) {
          this.studentOption = null
          this.infoForm = {
            student_id: '', //学生id
            day: yeartime(new Date()), // 检查日期
            healthy: '', // 健康状况
            handle: '' // 处理
          }
          this.$message.success('提交成功')
          this.$emit('InitFn')
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    // 关闭弹窗
    closePOpup() {
      this.$emit('update:visible', false)
    },
    getJson(option) {
      return JSON.parse(JSON.stringify(option))
    },
  },
  mounted() {
  }
}
</script>
<style scoped>
#cornerComment {
  height: 100vh;
  width: 100%;
  position: fixed;
  top: 0;
  left: 0;
  background: rgba(0, 0, 0, .5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9;
}

.cornerComment-in {
  width: 80%;
  height: 70%;
  background: #fff;
  display: flex;
  flex-direction: column;
  border-radius: 5px;
}

.cornerComment-in-title {
  height: 50px;
  display: flex;
  align-items: center;
  border-bottom: 1px solid #ddd;
  font-size: 24px;
}

.cornerComment-in-title span {
  padding: 0 10px;
}

.cornerComment-in-title span:first-child {
  flex: 1;
  font-size: 16px;
}

.cornerComment-in-footer {
  height: 50px;
  border-top: 1px solid #ddd;
  display: flex;
  align-items: center;
  padding: 0 10px;
  justify-content: center;
}

.commentBody {
  padding: 10px 20px;
  flex: 1;
  overflow-y: auto;
}

.close-Btn-line {
  cursor: pointer;
}

.resruitment-title {
  padding: 5px 0;
  border-bottom: 2px solid #abd3f3;
  margin-bottom: 20px;
}

.el-radio {
  margin-right: 20px;
}

.jobTime {
  display: flex;
  align-items: center;
}

.jobTime span {
  padding: 0 10px;
}

.allday-box {
  display: flex;
}

.allday-box-left {
  flex: 1;
}

.allday-box-right {
  width: 400px;
  padding-left: 20px;
  border-left: 1px solid #ddd;
}

.allday-student {
  overflow-y: auto;
}

.allday-student {
  overflow: hidden;
}

.allday-student-list {
  float: left;
  padding: 5px;
}

.allday-student-list-in {
  width: 100px;
  height: 40px;
  border: 1px solid #ddd;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  cursor: pointer;
  box-shadow: 0 2px 2px #ffdabf;
}

.allday-student-list-in:hover {
  background: #ef6f14;
  color: #fff;
  font-weight: bold;
}

.allday-student-list-in.active {
  background: #ef6f14;
  border: 1px solid #ef6f14;
  color: #fff;
  font-weight: bold;
}

.none-data-student {
  text-align: center;
  padding: 30px 0;
}
</style>

<!--<div class="allday-student" :style="{height: tableHeight+'px'}">-->
<!--<div class="allday-student-list" v-for="item in 40" :key="item">-->
<!--  <div class="allday-student-list-in">-->
<!--    <span>王力宏</span>-->
<!--    <i class="iconfont iconqueren-zhengque"></i>-->
<!--  </div>-->
<!--</div>-->
<!--</div>-->
